**labelling variables and data
label define Lpopn3 1 "MEDICAL PATIENTS" 2 "EMERGENCY DEPARTMENT PATIENTS" 
label value popn3 Lpopn3
label variable popn3 "Patient population"

label define Lecon_class1 1 "LIC" 2 "LMIC" 3 "UMIC"
label value econ_class1 Lecon_class1
label variable econ_class1 "Economic classification"

label variable sid "Study ID"

label variable site "Country" 

label variable popn_hiv_prev_cat1 "Adult HIV population prevalence (%)"
label define Lpopn_hiv_prev_cat1 1 "0-1" 2 "1-5" 3 "6-10" 4 "11-15" 5 "16-20" 6 "21-25"
label value popn_hiv_prev_cat1 Lpopn_hiv_prev_cat1

label define Lnos_cat 1 "Very high risk" 2 "High risk" 3 "High Quality"
label value nos_cat Lnos_cat
label variable nos_cat "Risk of bias"


*HIV  prevalence meta-analysis
metan hiv_summ_num hiv_summ_den, transform(logit)  hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV, just(left) bexpand size(3)) rfdist rflevel(95) nooverall  scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))



**HIV sub-group analyses
*HIV by country prevalence
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) by(popn_hiv_prev_cat1) proportion random ilevel(95) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(10, 20, 30, 40, 50, 60, 70)  forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV by country-level HIV prevalence, just(left) bexpand size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV by region
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(region) olevel(95) lcols(sid site) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV by region, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV by econ_classification
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) by(econ_class1) proportion random ilevel(95) olevel(95) lcols(sid site ) sortby(popn_hiv_prev_cat1 site year) counts denominator(100) xlabel(10, 20, 30, 40, 50, 60, 70)  forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV by country-level economic status, just(left) bexpand  size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV by quality 
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) by(nos_cat) proportion random ilevel(95) olevel(95) lcols(sid site  ) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70)  forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV by risk of bias, just(left) bexpand  size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV sensitivity analyses
metan hiv_summ_num hiv_summ_den if nos_cat!=1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV, just(left) bexpand size(3)) rfdist scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nooverall

*HIV METAFUNNEL and BIAS
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV, size(3)) rfdist rflevel(95)  

metafunnel _ES _seES, xtitle("Logit(proportion)") ytitle("Logit(standard error of proportion") subtitle("Funnel plot for prevalence of HIV with pseudo 95% confidence limits", size(3))

metabias _ES _seES, egger

**HIV METAREGRESSION
metan hiv_summ_num hiv_summ_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV, size(3)) rfdist rflevel(95)  
metareg _ES, wsse(_seES) eform
metareg _ES ave_age, wsse(_seES) eform
metareg _ES prop_female, wsse(_seES) eform
metareg _ES start_year, wsse(_seES) eform
metareg _ES popn_hiv_prev_cat1, wsse(_seES) eform
metareg _ES econ_class1, wsse(_seES) eform
xi: metareg _ES i.econ_class1, wsse(_seES) eform
xi: metareg _ES nos_cat, wsse(_seES) eform
metareg _ES popn_hiv_prev, wsse(_seES) eform

xi: metareg _ES popn_hiv_prev i.econ_class1, wsse(_seES) eform

metareg _ES popn3 econ_class2 nos_cat popn_hiv_prev, wsse(_seES) eform


*HIV treatment failure meta-analysis
metan rxfailure_num rxfailure_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV treatment failure, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV status unaware beginning, meta-analysis
metan hiv_unaware_beg_num hiv_unaware_beg_den, transform(logit) hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Unknown HIV status (on admission), just(left) bexpand  size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV new diagnosis meta-analysis
metan hiv_new_num hiv_new_den, transform(logit) citype(exact) hksj proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(New HIV diagnoses, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV status unaware end meta-analysis
metan hiv_unaware_end_num hiv_unaware_end_den, transform(logit) hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60, 70) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Unknown HIV status (on discharge), just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HIV treatment non-compliance meta-analysis
metan rxcomp_num rxcomp_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site econ_class1 popn_hiv_prev_cat1) sortby(popn_hiv_prev_cat1 econ_class1 site year) counts denominator(100) xlabel(20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(HIV treatment non-compliance among patients on ART, size(3) just(left) bexpand) rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))


* Hypertension (HTN) meta-analysis
metan htn_summ_num htn_summ_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Hypertension, size(3) just(left) bexpand ) rfdist rflevel(95) nooverall  scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

**Hypertension sub-group analyses
*HTN by region
metan htn_summ_num htn_summ_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(region) lcols(sid site) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Hypertension by region, size(3) just(left) bexpand  ) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))


*HTN by economic class
metan htn_summ_num htn_summ_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(econ_class1) lcols(sid site) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Hypertension by country-level economic status, size(3) just(left) bexpand  ) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

* HTN by risk of bias
metan htn_summ_num htn_summ_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(nos_cat) lcols(sid site  ) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Hypertension by risk of bias, just(left) bexpand  size(3)) rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nooverall



*HTN sensitivity analyses
metan htn_summ_num htn_summ_den if nos_cat!=1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Hypertension, size(3) just(left) bexpand   ) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HYPERTENSION METAFUNNEL and BIAS
metan htn_summ_num htn_summ_den if popn3==1, hksj transform(logit) citype(exact) proportion 
metafunnel _ES _seES, xtitle("Logit(proportion)") ytitle("Logit(standard error of proportion") subtitle("Funnel plot for prevalence of hypertension with pseudo 95% confidence limits", size(3))

metabias _ES _seES, egger

**HYPERTENSION METAREGRESSION
metan htn_summ_num htn_summ_den if popn3==1, hksj transform(logit) citype(exact) proportion 
metareg _ES, wsse(_seES) eform
metareg _ES ave_age, wsse(_seES) eform
metareg _ES prop_female, wsse(_seES) eform
metareg _ES popn_hiv_prev_cat1, wsse(_seES) eform
metareg _ES start_year, wsse(_seES) eform
metareg _ES econ_class1, wsse(_seES) eform


xi: metareg _ES i.econ_class1, wsse(_seES) eform
xi: metareg _ES i.region, wsse(_seES) eform
xi: metareg _ES nos_cat, wsse(_seES) eform
metareg _ES popn_hiv_prev, wsse(_seES) eform

*HTN presentations (emergencies)
metan htn_pres_num htn_pres_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Acute hypertensive presentations, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*HTN presentation by region
metan htn_pres_num htn_pres_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(region) lcols(sid site) sortby(econ_class1 year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Acute hypertensive presentations by region, just(left) bexpand  size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))




*Diabetes (DM) meta-analysis
metan dm_oldnew_num dm_oldnew_den, transform(logit) citype(exact) hksj proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40 ) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes, just(left) bexpand size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 


**DM sub-group analyses
*DM by region
metan dm_oldnew_num dm_oldnew_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(region) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40 ) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes by region, just(left) bexpand size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 

*DM by risk of bias
metan dm_oldnew_num dm_oldnew_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(nos_cat) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes by risk of bias, just(left) bexpand size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 

*DM by economic status
metan dm_oldnew_num dm_oldnew_den if popn3==1, transform(logit) hksj citype(exact) by(econ_class1) proportion random ilevel(95) olevel(95) lcols(sid site) sortby(popn_hiv_prev_cat1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force  forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes by country-level economic status, just(left) bexpand  size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*DIABETES SENSITIVITY ANALYSES
metan dm_oldnew_num dm_oldnew_den if nos_cat!=1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40 ) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes, just(left) bexpand size(3)) rfdist nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 


*DIABETES METAFUNNEL and BIAS
metan dm_oldnew_num dm_oldnew_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes, size(3)) rfdist rflevel(95)  

metafunnel _ES _seES,  xtitle("Logit(proportion)") ytitle("Logit(standard error of proportion)") subtitle("Funnel plot for prevalence of diabetes with pseudo 95% confidence limits", size(3))

metabias _ES _seES, egger

**DIABETES METAREGRESSION
metan dm_oldnew_num dm_oldnew_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabetes, size(3)) rfdist rflevel(95)  
metareg _ES, wsse(_seES) eform
metareg _ES ave_age, wsse(_seES) eform
metareg _ES prop_female, wsse(_seES) eform
metareg _ES econ_class1, wsse(_seES) eform
metareg _ES start_year, wsse(_seES) eform
metareg _ES region, wsse(_seES) eform

xi: metareg _ES i.popn3, wsse(_seES) eform
xi: metareg _ES econ_class1, wsse(_seES) eform
xi: metareg _ES hiv_summ_, wsse(_seES) eform

xi: metareg _ES i.nos_cat, wsse(_seES) eform


*Diabetic emergencies meta-analysis 
metan dm_pres_num dm_pres_den, transform(logit) citype(exact) hksj proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40 ) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Diabeteic emergencies, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 

*heart failure (hf) meta-analysis
metan hf_pres_num hf_pres_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Heart failure, just(left) bexpand size(3)) by(popn3) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

**heart failure sub-group analyses
*hf by region
metan hf_pres_num hf_pres_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site)  by(region) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Heart failure by region, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*hf by economic status
metan hf_pres_num hf_pres_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site)  by(econ_class1) sortby( year site _ES) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Heart failure by country-level economic status, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*hf by risk of bias
metan hf_pres_num hf_pres_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site)  by(nos_cat) sortby( year site _ES) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Heart failure by risk of bias, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*hf sensitivity analysis
metan hf_pres_num hf_pres_den if nos_cat!=1,hksj  transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site)  by(popn3) sortby( year site _ES) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Heart failure, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*hf funnel plot
metan hf_pres_num hf_pres_den, by(popn3) transform(logit) citype(exact) proportion random ilevel(95) 

metafunnel _ES _seES,  xtitle("Logit(proportion)") ytitle("Logit(standard error of proportion)") subtitle("Funnel plot for prevalence of heart failure with pseudo 95% confidence limits", size(3))

metabias _ES _seES, egger

*hf metaregregression
metan hf_pres_num hf_pres_den if popn3==1, hksj transform(logit) citype(exact) proportion random ilevel(95) 
metareg _ES, wsse(_seES) eform
metareg _ES ave_age, wsse(_seES) eform
metareg _ES prop_female, wsse(_seES) eform
metareg _ES econ_class1, wsse(_seES) eform
metareg _ES start_year, wsse(_seES) eform
xi: metareg _ES i.region, wsse(_seES) eform
xi: metareg _ES i.econ_class1, wsse(_seES) eform
xi: metareg _ES hiv_summ_, wsse(_seES) eform

*hypertensive heart disease meta-analysis
metan hhd_new_num hhd_new_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) by(popn3) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Prevalence of Hypertensive heart disease, just(left) bexpand size(3))  rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nohet nooveral


*Stroke meta-analysis
metan stroke_new_num stroke_new_den, transform(logit) citype(exact) hksj proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30,) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Stroke, just(left) bexpand size(3)) nooverall rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 


**Stroke sub-group analyses

*stroke by region
metan stroke_new_num stroke_new_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(region) olevel(95) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Stroke by region, just(left) bexpand size(3)) nooverall rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*stroke by economic classification
metan stroke_new_num stroke_new_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(econ_class1) olevel(95) lcols(sid site) sortby(year site econ_class1) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Stroke by country-level economic status, just(left) bexpand size(3)) nooverall rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*stroke by risk of bias
metan stroke_new_num stroke_new_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(nos_cat) olevel(95) lcols(sid site) sortby(year site econ_class1) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Stroke by risk of bias, just(left) bexpand size(3)) nooverall rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*stroke sensitivity analysis
metan stroke_new_num stroke_new_den if nos_cat!=1, transform(logit) hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site) sortby(year site econ_class1) counts denominator(100) xlabel(0, 10, 20, 30, 40) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Stroke, just(left) bexpand size(3)) nooverall rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*stroke funnel plot
metan stroke_new_num stroke_new_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) 

metafunnel _ES _seES,  xtitle("Logit(proportion)") ytitle("Logit(standard error of proportion)") subtitle("Funnel plot for prevalence of stroke with pseudo 95% confidence limits", size(3))

metabias _ES _seES, egger


*stroke metaregregression
metan stroke_new_num stroke_new_den if popn3==1, transform(logit) hksj citype(exact) proportion random ilevel(95) 
metareg _ES, wsse(_seES) eform
metareg _ES ave_age, wsse(_seES) eform
metareg _ES prop_female, wsse(_seES) eform
metareg _ES econ_class1, wsse(_seES) eform
metareg _ES start_year, wsse(_seES) eform
xi: metareg _ES i.region, wsse(_seES) eform
xi: metareg _ES i.econ_class1, wsse(_seES) eform
xi: metareg _ES hiv_summ_, wsse(_seES) eform



*acute coronary syndrome meta-analysis
metan ihd_new_num ihd_new_den, transform(logit) hksj citype(exact) proportion random ilevel(95) by(popn3) olevel(95) lcols(sid site ) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Acute coronary syndromes, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*Chronic kidney diseases (CKD) meta-analysis
metan ckd_oldnew_num ckd_oldnew_den, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) by(popn3) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Chronic kidney disease, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 

*Acute kidney injury meta-analysis
metan renal_pres_num renal_pres_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year ) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Acute kidney injury, just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*Unclassified renal impairment meta-analysis
metan renal_summ_num renal_summ_den, transform(logit) hksj citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year ) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Renal impairment (unclassified), just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))

*chronic liver diseaese meta-analysis
metan cirrhosis_pres_num cirrhosis_pres_den, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) by(popn3) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Chronic liver disease, just(left) bexpand size(3)) rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nooverall

*COPD meta-analysis
metan copd_pres_num copd_pres_den, hksj transform(ftukey) citype(exact) proportion random ilevel(95) olevel(95) lcols(sid site) by(popn3) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30 ) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Chronic obstructive pulmonary disease (COPD), just(left) bexpand size(3)) rfdist rflevel(95) nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) 

*obesity meta-analysis
metan ob_num ob_den, hksj transform(logit) citype(exact) proportion lcols(sid site econ_class1) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20) force forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Obesity, just(left) bexpand size(3)) by(popn3) rfdist rflevel(95)  scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nooverall

*current smoker meta-analysis
metan smok_num smok_den, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 year) counts denominator(100) xlabel(0, 10, 20, 30, 40) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Tobacco smokers, just(left) bexpand size(3)) rfdist rflevel(95) scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white)) nooverall

*alcohol (etoh) meta-analysis
metan etoh_old_num etoh_old_den, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Alcohol use, just(left) bexpand size(3)) rfdist rflevel(95) nohet nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))  

*Admission due to alcohol  meta-analysis
metan etoh_pc_num etoh_pc_den, hksj transform(logit) citype(exact) proportion random ilevel(95) olevel(95) by(popn3) lcols(sid site) sortby(econ_class1 site year) counts denominator(100) xlabel(0, 10, 20, 30, 40, 50, 60) forestplot(leftjustify) xtitle("Prevalence (%)", size(2)) title(Admission due to alcohol use, just(left) bexpand size(3)) rfdist rflevel(95) nohet nooverall scheme(s1color) graphregion(lcolor(white) lpattern(blank) ifcolor(white) ilpattern(blank)) plotregion(lcolor(white) ilcolor(white))  







